/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ultrasoft.farmasoft.domain;

import java.io.Serializable;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author Administrador
 */
@Entity
@Table(name = "providerpharmacy")
@NamedQueries({
    @NamedQuery(name = "Providerpharmacy.findAll", query = "SELECT p FROM Providerpharmacy p"),
    @NamedQuery(name = "Providerpharmacy.findByProviderId", query = "SELECT p FROM Providerpharmacy p WHERE p.providerpharmacyPK.providerId = :providerId"),
    @NamedQuery(name = "Providerpharmacy.findByProviderIdByPharmacyId", query = "SELECT p FROM Providerpharmacy p WHERE p.providerpharmacyPK.providerId = :providerId AND p.providerpharmacyPK.pharmacyId = :pharmacyId"),
    @NamedQuery(name = "Providerpharmacy.findByPharmacyIdByActive", query = "SELECT p FROM Providerpharmacy p WHERE p.providerpharmacyPK.pharmacyId = :pharmacyId AND p.provider.active = :active order by p.provider.name"),
    @NamedQuery(name = "Providerpharmacy.findByPharmacyId", query = "SELECT p FROM Providerpharmacy p WHERE p.providerpharmacyPK.pharmacyId = :pharmacyId")})
public class Providerpharmacy implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ProviderpharmacyPK providerpharmacyPK;
    
    @JoinColumn(name = "pharmacyId", referencedColumnName = "pharmacyId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Pharmacy pharmacy;
    @JoinColumn(name = "providerId", referencedColumnName = "providerId", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Provider provider;

    public Providerpharmacy() {
    }

    public Providerpharmacy(ProviderpharmacyPK providerpharmacyPK) {
        this.providerpharmacyPK = providerpharmacyPK;
    }

    public Providerpharmacy(int providerId, int pharmacyId) {
        this.providerpharmacyPK = new ProviderpharmacyPK(providerId, pharmacyId);
    }

    public Providerpharmacy(Provider provider,Pharmacy pharmacy) {
        this.providerpharmacyPK = new ProviderpharmacyPK(provider.getProviderId(), pharmacy.getPharmacyId());
    }
    
    public ProviderpharmacyPK getProviderpharmacyPK() {
        return providerpharmacyPK;
    }

    public void setProviderpharmacyPK(ProviderpharmacyPK providerpharmacyPK) {
        this.providerpharmacyPK = providerpharmacyPK;
    }

    public Pharmacy getPharmacy() {
        return pharmacy;
    }

    public void setPharmacy(Pharmacy pharmacy) {
        this.pharmacy = pharmacy;
    }

    public Provider getProvider() {
        return provider;
    }

    public void setProvider(Provider provider) {
        this.provider = provider;
    }
/*
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (providerpharmacyPK != null ? providerpharmacyPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Providerpharmacy)) {
            return false;
        }
        Providerpharmacy other = (Providerpharmacy) object;
        if ((this.providerpharmacyPK == null && other.providerpharmacyPK != null) || (this.providerpharmacyPK != null && !this.providerpharmacyPK.equals(other.providerpharmacyPK))) {
            return false;
        }
        return true;
    }

    @Override	*/
    public String toString() {
        return "com.ultrasoft.farmasoft.domain.Providerpharmacy[ providerpharmacyPK=" + providerpharmacyPK + " ]";
    }
    
}
